package com.itheima.health.common;

import com.itheima.health.dao.MemberDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MemberReport {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private RedisTemplate redisTemplate;
    @Scheduled(cron = "* * 0 * * ?")//每天0点执行 去数据库查询 会员总数的任务，并将查询结果存入redis
    public void getCountTotalMembers(){
        Integer countTotalMembers = memberDao.getCountTotalMembers();
        redisTemplate.opsForValue().set("countTotalMembers",countTotalMembers);
    }
}
